//
//  PMSpace.h
//  PezMonkey
//
//  Created by Spence DiNicolantonio on 11/2/09.
//  Copyright 2009 Necrosoft. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "PMCore.h"

@class PMBody, PMShape, PMJoint;


@interface PMSpace : NSObject {
@protected
	// Chipmunk space reference
	cpSpace *space;
	
@private
	// Set of rigid bodies in the space
	NSMutableSet *bodies;
	
	// Set of active collision shapes in the space
	NSMutableSet *activeShapes;
	
	// Set of static sollision shapes in the space
	NSMutableSet *staticShapes;
	
	// Set of joints in the space
	NSMutableSet *joints;
	
	// The number of simulation steps to take for any given time interval
	NSUInteger stepsPerFrame;
}

@property (assign) NSUInteger stepsPerFrame;


#pragma mark Init
- (id)initWithGravity:(PMVect)gravity;


#pragma mark -
#pragma mark Getters
- (cpSpace *)cpSpace;
- (NSUInteger)iterations;
- (NSUInteger)elasticIterations;
- (PMVect)gravity;
- (PMFloat)damping;
- (NSUInteger)steps;
- (NSArray *)bodies;
- (NSArray *)shapes;
- (NSArray *)activeShapes;
- (NSArray *)staticShapes;
- (NSArray *)allShapes;
- (NSArray *)joints;


#pragma mark -
#pragma mark Setters
- (void)setIterations:(NSUInteger)iterations;
- (void)setElasticIterations:(NSUInteger)elasticIterations;
- (void)setGravity:(PMVect)gravity;
- (void)setDamping:(PMFloat)damping;


#pragma mark -
#pragma mark Add Elements
- (void)addBody:(PMBody *)body;
- (void)addShape:(PMShape *)shape isStatic:(BOOL)isStatic;
- (void)addShape:(PMShape *)shape;
- (void)addActiveShape:(PMShape *)shape;
- (void)addStaticShape:(PMShape *)shape;
- (void)addJoint:(PMJoint *)joint;


#pragma mark -
#pragma mark Remove Elements
- (void)removeBody:(PMBody *)body;
- (void)removeShape:(PMShape *)shape;
- (void)removeShapeAndBody:(PMShape *)shape;
- (void)removeJoint:(PMJoint *)joint;
- (void)removeAllBodies;
- (void)removeAllShapes;
- (void)removeAllJoints;
- (void)removeAll;


#pragma mark -
#pragma mark Queries
- (BOOL)containsBody:(PMBody *)body;
- (BOOL)containsShape:(PMShape *)shape;
- (BOOL)containsActiveShape:(PMShape *)shape;
- (BOOL)containsStaticShape:(PMShape *)shape;
- (BOOL)containsJoint:(PMJoint *)joint;


#pragma mark -
#pragma mark Spacial Hash
- (void)setActiveHashSize:(NSUInteger)size cellDimension:(PMFloat)cellDimension;
- (void)setStaticHashSize:(NSUInteger)size cellDimension:(PMFloat)cellDimension;
- (void)rehashStatic;


#pragma mark -
#pragma mark Step
- (void)step:(NSTimeInterval)deltaT;

@end
